//
//  CharacterIconViewController.m
//  PacIsBack
//
//  Created by Simon André on 12/02/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CharacterIconViewController.h"
#import "CharacterProtocol.h"
#import "Constants.h"
#import "RPGImageView.h"


@implementation CharacterIconViewController

@synthesize character;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

-(id) initForCharacter:(id<CharacterProtocol>) shownCharacter{
	if (self = [super init]) {
		[self setCharacter:shownCharacter];
		UIView* emptyView = [[UIView alloc] initWithFrame:CGRectMake(characterIconPositionX, characterIconPositionY, characterIconWidth, characterIconHeight)];
		[self setView:emptyView];
		[emptyView release];
		NSString* imageName = [NSString stringWithFormat:@"%@%@",[[self character] characterType],@"Head.png"];
		UIImage* characterImage = [UIImage imageNamed:imageName];
		UIImageView* characterIconImage = [[RPGImageView alloc] init];
		[characterIconImage setImage:characterImage];
		[characterIconImage sizeToFit];
		[[self view] addSubview:characterIconImage];
		[characterIconImage release];
		UIFont* font = [UIFont fontWithName:@"MarkerFelt-Thin" size:9.0];
		CGFloat textNameHeight = [[[self character] characterType] sizeWithFont:font].height;
		UILabel* characterNameView = [[UILabel alloc] initWithFrame:CGRectMake(0.0, characterHeadImageHeight, characterHeadImageWidth, textNameHeight)];
		[characterNameView setText:[[self character] characterType]];
		[characterNameView setBackgroundColor:[UIColor clearColor]];
		[characterNameView setTextAlignment:UITextAlignmentCenter];
		[characterNameView setFont:font];
		[[self view] addSubview:characterNameView];
		[characterNameView release];
		UILabel* characterHPView = [[UILabel alloc] initWithFrame:CGRectMake(0.0, characterHeadImageHeight+textNameHeight, characterHeadImageWidth, textNameHeight)];
		[characterHPView setText:[NSString stringWithFormat:@"%d%@%d",[[self character] currentHP],@"/",[[self character] maxHP]]];
		[characterHPView setBackgroundColor:[UIColor clearColor]];
		[characterHPView setTextAlignment:UITextAlignmentCenter];
		[characterHPView setFont:font];
		[[self view] addSubview:characterHPView];
		[characterHPView release];
		UILabel* characterManaView = [[UILabel alloc] initWithFrame:CGRectMake(0.0, characterHeadImageHeight+(2*textNameHeight), characterHeadImageWidth, textNameHeight)];
		[characterManaView setText:[NSString stringWithFormat:@"%d%@%d",[[self character] currentMP],@"/",[[self character] maxMP]]];
		[characterManaView setBackgroundColor:[UIColor clearColor]];
		[characterManaView setTextAlignment:UITextAlignmentCenter];
		[characterManaView setFont:font];
		[[self view] addSubview:characterManaView];
		[characterManaView release];
	}
	return self;
}

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[self setCharacter:nil];
	[super dealloc];
}


@end
